#region Using Statements
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace SkyBurner.Screens
{
    public partial class SkyBurnerScreenBase : BaseDrawableObject
    {
        protected class ScreenButton
        {
            private Vector2 m_vPosition;
            private Texture2D m_selectedTexture;
            private Texture2D m_notSelectedTexture;
            private bool m_bSelected;
            private int m_nButtonID;            

            public int ID
            {
                get { return m_nButtonID; }
            }

            public bool Selected
            {
                get { return m_bSelected; }
                set { m_bSelected = value; }
            }

            public ScreenButton(Vector2 vPosition, Texture2D pSelectedTexture, Texture2D pNotSelectedTexture, int nButtonID, bool bSelected)
            {
                m_vPosition = vPosition;
                m_selectedTexture = pSelectedTexture;
                m_notSelectedTexture = pNotSelectedTexture;
                m_nButtonID = nButtonID;
                m_bSelected = bSelected;
            }

            public void Draw(GraphicsDevice pGraphicsDevice, SpriteBatch pSpriteBatch)
            {
                if (m_bSelected)
                    pSpriteBatch.Draw(m_selectedTexture, m_vPosition, Color.White);
                else
                    pSpriteBatch.Draw(m_notSelectedTexture, m_vPosition, Color.White);
            }
        }

        protected Texture2D m_screenTexture;
        protected Collection<ScreenButton> m_buttonsList = new Collection<ScreenButton>();
        protected ScreenManager m_screenManager;
        protected int m_nScreenID;
        protected bool m_bActive;

        public SkyBurnerScreenID ID
        {
            get { return (SkyBurnerScreenID)m_nScreenID; }
        }

        public Texture2D ScreenTexture
        {
            get { return m_screenTexture; }
            set { m_screenTexture = value; }
        }

        public bool Active
        {
            get { return m_bActive; }
            set { m_bActive = value; }
        }

        public SkyBurnerScreenBase(BaseGame game, ScreenManager pScreenManager, int nScreenID, bool bActive)
            : base(game)
        {
            m_screenManager = pScreenManager;
            m_nScreenID = nScreenID;
            m_bActive = bActive;

            game.RegisterObject(this);
        }

        public override void OnDeviceReset()
        {
            base.OnDeviceReset();
        }

        public void AddButton(Vector2 vPosition, Texture2D pSelectedTexture, Texture2D pNotSelectedTexture, int nButtonID, bool bSelected)
        {
            m_buttonsList.Add(new ScreenButton(vPosition, pSelectedTexture, pNotSelectedTexture, nButtonID, bSelected));
        }

        public void SelectButtonByID(int nButtonID)
        {
            foreach (ScreenButton button in m_buttonsList)
                button.Selected = (button.ID == nButtonID);
        }

        public virtual void Activate()
        {
            m_bActive = true;
        }

        public virtual void Deactivate()
        {
            m_bActive = false;
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime, Camera pActiveCamera)
        {
            base.Update(gameTime, pActiveCamera);
        }

        public override void Draw(GameTime gameTime, Camera pActiveCamera)
        {
            m_Game.SpriteBatch.Begin();

            // draw the screen...
            m_Game.SpriteBatch.Draw(m_screenTexture, new Rectangle(0, 0, m_Game.GraphicsDevice.Viewport.Width, m_Game.GraphicsDevice.Viewport.Height), Color.White);

            // draw buttons...
            foreach (ScreenButton button in m_buttonsList)
                button.Draw(m_Game.GraphicsDevice, m_Game.SpriteBatch);

            m_Game.SpriteBatch.End();

            base.Draw(gameTime, pActiveCamera);
        }
    }
}
